#import "sprite_game_enemy.h"

#import "sprite_game_enemy_0.h"
#import "sprite_game_enemy_1.h"
#import "sprite_game_enemy_2.h"
#import "sprite_game_enemy_3.h"
#import "sprite_game_enemy_4.h"
#import "sprite_game_enemy_5.h"
#import "sprite_game_enemy_6.h"
#import "sprite_game_enemy_7.h"
#import "sprite_game_enemy_boss1.h"
#import "sprite_game_enemy_boss2.h"
#import "sprite_game_enemy_boss3.h"

@implementation SpriteGameEnemy

+ (id)createEnemy:(int)Type
{
}

- (id)initSpriteGameEnemy:(SMissionEnemy *)InfoData
{
	if ((self = [super initSpriteGameObject]))
	{
		objectName_ = "object sprite game enemy base";
		
		/*set up base data
		*/
		aiType_ = InfoData->ai_type;
		moveSpeed_ = InfoData->move_speed;
		moveSpeedVariance_ = InfoData->move_speed_variance;
		standTime_ = InfoData->stand_time;
		
		/*born position or move path
		*/
		switch (aiType_)
		{
		case ENEMY_AI_TYPE_0:
		case ENEMY_AI_TYPE_1:
			_PathIter = InfoData->move_path_table.begin();
			for (; _PathIter != InfoData->move_path_table.end(); _PathIter++)
			{
				switch (_PathIter->path_type)
				{
				case MISSION_ENEMY_PATH_ELEMENT_AREA_INDEX: movePath_.push_back(CfgGameGetPointCGPoint(_PathIter->area_index)); break;
				case MISSION_ENEMY_PATH_ELEMENT_POINT: movePath_.push_back(_PathIter->point); break;
				default:;
				}
			}
			self.positionInPixels = movePath_.front();
			movePath_.pop_front();
			break;
		case ENEMY_AI_TYPE_2:
			switch (InfoData->born_area.path_type)
			{
			case MISSION_ENEMY_PATH_ELEMENT_AREA_INDEX: self.positionInPixels = CfgGameGetPointCGPoint(InfoData->born_area.area_index); break;
			case MISSION_ENEMY_PATH_ELEMENT_POINT: self.positionInPixels = InfoData->born_area.point; break;
			default:;
			}
			break;
		case ENEMY_AI_TYPE_3: self.positionInPixels = g_CfgGameScrrenArea[InfoData->born_area.area_index].center; break;
		default:;
		}
		
		/*flag
		*/
		state_ = ENEMY_STATE_INVALID;
	}
	return self;
}

- (float)GetMoveSpeed
{
	float _Ret;
	float _SpeedVariance;

	if (moveSpeedVariance_ == 0)
	{
		return moveSpeed_;
	}
	else
	{
		_SpeedVariance = rand();
		_SpeedVariance = fmodf(_SpeedVariance, moveSpeedVariance_);
		_SpeedVariance *= (rand() % 2 == 0 ? 1 : -1);
		_Ret = fabsf(moveSpeed_ + _SpeedVariance);
		return _Ret;
	}
}

- (void)PlayAni:(int)Type
{
	CCSequence *_SeqBoss3Appear;
	id _ActionBoss3Appear;
	CCCallFuncN *_CallBackBoss3Appear;
	CCSequence *_SeqBoss3EyeOpen;
	id _ActionBoss3EyeOpen;
	CCCallFuncN *_CallBackBoss3EyeOpen;
	CCSequence *_SeqBoss3EyeClose;
	id _ActionBoss3EyeClose;
	CCCallFuncN *_CallBackBoss3EyeClose;

	_Animation = nil;
	switch (Type)
	{
	case ENEMY_ANI_MOVE:
		switch (type_)
		{
		case ENEMY_TYPE_0:
		case ENEMY_TYPE_1:
		case ENEMY_TYPE_2:
		case ENEMY_TYPE_3:
		case ENEMY_TYPE_4:
		case ENEMY_TYPE_5:
		case ENEMY_TYPE_6:
		case ENEMY_TYPE_7: _Animation = uiCreateAnimationObject(&g_CfgGameEnemyDataTable[type_].ani_move); break;
		case ENEMY_TYPE_BOSS_1: _Animation = uiCreateAnimationObject(&g_CfgGameBoss1Data.ani_move); break;
		case ENEMY_TYPE_BOSS_2: _Animation = uiCreateAnimationObject(&g_CfgGameBoss2Data.ani_move); break;
		case ENEMY_TYPE_BOSS_3: _Animation = uiCreateAnimationObject(&g_CfgGameBoss3Data.ani_move); break;
		default:;
		}
		if (nil != _Animation)
		{
			_ActionMove = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:_Animation]];
			[image_ runAction:_ActionMove];
		}
		break;
	case ENEMY_ANI_ATTACK:
		_CallBackAttack = [CCCallFuncN actionWithTarget:self selector:@selector(CallBackActionAttackOver:)];
		switch (type_)
		{
		case ENEMY_TYPE_0:
		case ENEMY_TYPE_1:
		case ENEMY_TYPE_2:
		case ENEMY_TYPE_3:
		case ENEMY_TYPE_4:
		case ENEMY_TYPE_5:
		case ENEMY_TYPE_6:
		case ENEMY_TYPE_7: _Animation = uiCreateAnimationObject(&g_CfgGameEnemyDataTable[type_].ani_attack); break;
		case ENEMY_TYPE_BOSS_1: _Animation = uiCreateAnimationObject(&g_CfgGameBoss1Data.ani_attack); break;
		case ENEMY_TYPE_BOSS_2: _Animation = uiCreateAnimationObject(&g_CfgGameBoss2Data.ani_attack); break;
		case ENEMY_TYPE_BOSS_3: _Animation = uiCreateAnimationObject(&g_CfgGameBoss3Data.ani_attack); break;
		default:;
		}
		if (nil != _Animation)
		{
			_ActionAttack = [CCAnimate actionWithAnimation:_Animation];
			_SeqAttack = [CCSequence actions:_ActionAttack, _CallBackAttack, nil];
		}
		else
		{
			_SeqAttack = [CCSequence actions:_CallBackAttack, nil];
		}
		[image_ runAction:_SeqAttack];
		break;
	case ENEMY_ANI_DIE:
		// self.color = ccWHITE;
		_CallBackDie = [CCCallFuncN actionWithTarget:self selector:@selector(CallBackActionDieOver:)];
		switch (type_)
		{
		case ENEMY_TYPE_0:
		case ENEMY_TYPE_1:
		case ENEMY_TYPE_2:
		case ENEMY_TYPE_3:
		case ENEMY_TYPE_4:
		case ENEMY_TYPE_5:
		case ENEMY_TYPE_6:
		case ENEMY_TYPE_7: _Animation = uiCreateAnimationObject(&g_CfgGameEnemyDataTable[type_].ani_die); break;
		case ENEMY_TYPE_BOSS_1: break;
		case ENEMY_TYPE_BOSS_2: _Animation = uiCreateAnimationObject(&g_CfgGameBoss2Data.ani_die); break;
		case ENEMY_TYPE_BOSS_3: break;
		default:;
		}
		if (nil != _Animation)
		{
			_ActionDie = [CCAnimate actionWithAnimation:_Animation];
			_SeqDie = [CCSequence actions:_ActionDie, _CallBackDie, nil];
		}
		else
		{
			_SeqDie = [CCSequence actions:_CallBackDie, nil];
		}
		[image_ runAction:_SeqDie];
		break;
	case ENEMY_ANI_BOSS_3_APPEAR:
		_Animation = uiCreateAnimationObject(&g_CfgGameBoss3Data.ani_appear);
		_ActionBoss3Appear = [CCAnimate actionWithAnimation:_Animation];
		_CallBackBoss3Appear = [CCCallFuncN actionWithTarget:self selector:@selector(CallBackBoss3ActionAppearAniOver:)];
		_SeqBoss3Appear = [CCSequence actions:_ActionBoss3Appear, _CallBackBoss3Appear, nil];
		[image_ runAction:_SeqBoss3Appear];
		break;
	case ENEMY_ANI_BOSS_3_EYE_OPEN:
		_Animation = uiCreateAnimationObject(&g_CfgGameBoss3Data.ani_eye_open);
		_ActionBoss3EyeOpen = [CCAnimate actionWithAnimation:_Animation];
		_CallBackBoss3EyeOpen = [CCCallFuncN actionWithTarget:self selector:@selector(CallBackBoss3ActionEyeOpenAniOver:)];
		_SeqBoss3EyeOpen = [CCSequence actions:_ActionBoss3EyeOpen, _CallBackBoss3EyeOpen, nil];
		[image_ runAction:_SeqBoss3EyeOpen];
		break;
	case ENEMY_ANI_BOSS_3_EYE_CLOSE:
		_Animation = uiCreateAnimationObject(&g_CfgGameBoss3Data.ani_eye_close);
		_ActionBoss3EyeClose = [CCAnimate actionWithAnimation:_Animation];
		_CallBackBoss3EyeClose = [CCCallFuncN actionWithTarget:self selector:@selector(CallBackBoss3ActionEyeCloseAniOver:)];
		_SeqBoss3EyeClose = [CCSequence actions:_ActionBoss3EyeClose, _CallBackBoss3EyeClose, nil];
		[image_ runAction:_SeqBoss3EyeClose];
		break;
	default:;
	}
}

- (void)aiCreate
{
	switch (aiType_)
	{
	case ENEMY_AI_TYPE_0:
	case ENEMY_AI_TYPE_1:[self ActionMovePath]; break;
	case ENEMY_AI_TYPE_2:
		switch (type_)
		{
		case ENEMY_TYPE_0:
		case ENEMY_TYPE_1:
		case ENEMY_TYPE_2:
		case ENEMY_TYPE_3:
		case ENEMY_TYPE_4:
		case ENEMY_TYPE_5:[self ActionMove]; break;
		case ENEMY_TYPE_6:
		case ENEMY_TYPE_7:
			if (nil != [self GetFreeHeart])
			{
				[self ActionAttack];
			}
			else
			{
				[self ActionMove];
			}
			break;
		case ENEMY_TYPE_BOSS_1:
			self.positionInPixels = g_CfgGameScrrenArea[14].center;
			[self ActionBoss1Appear];
			break;
		case ENEMY_TYPE_BOSS_2:
			self.positionInPixels = g_CfgGameScrrenArea[14].center;
			[self ActionBoss2Appear];
			break;
		case ENEMY_TYPE_BOSS_3:
			self.positionInPixels = g_CfgGameScrrenArea[14].center;
			boss3BornPoint_ = self.positionInPixels;
			[self ActionBoss3Appear];
			break;
		default:;
		}
		break;
	case ENEMY_AI_TYPE_3:[self ActionBoss3Slave]; break;
	default:;
	}
}

- (void)aiActionMoveOver
{
	switch (aiType_)
	{
	case ENEMY_AI_TYPE_0:
		if (movePath_.size() == 0)
		{
			/*enemy move to disapper point
			*/
			CMgrGameMission::Instance()->EventEnemyDisappear(self);
			/*remove self;
			*/
			[g_LayerGameObject RemoveEnemy:self];
		}
		else
		{
			[self ActionStand:standTime_];
		}
		break;
	case ENEMY_AI_TYPE_1:
		if (movePath_.size() == 0)
		{
			/*enemy move to disapper point
			*/
			CMgrGameMission::Instance()->EventEnemyDisappear(self);
			/*remove self;
			*/
			[g_LayerGameObject RemoveEnemy:self];
		}
		else
		{
			[self ActionAttack];
		}
		break;
	case ENEMY_AI_TYPE_2:
		switch (type_)
		{
		case ENEMY_TYPE_0:[self ActionStand:standTime_]; break;
		case ENEMY_TYPE_1:
		case ENEMY_TYPE_2:
		case ENEMY_TYPE_3:
		case ENEMY_TYPE_4:[self ActionAttack]; break;
		case ENEMY_TYPE_5:
			switch (rand() % 3)
			{
			case 0:[self ActionStand:1.0f]; break;
			case 1:[self ActionAttack]; break;
			case 2:[self ActionMove]; break;
			}
			break;
		case ENEMY_TYPE_6:
		case ENEMY_TYPE_7:
			if (nil != [self GetFreeHeart])
			{
				[self ActionAttack];
			}
			else
			{
				[self ActionMove];
			}
			break;
		case ENEMY_TYPE_BOSS_1:
		case ENEMY_TYPE_BOSS_2:
		case ENEMY_TYPE_BOSS_3:[self ActionAttack]; break;
		default:;
		}
		break;
	default:;
	}
}

- (void)aiActionStandOver
{
	/*if enemy is dead, just return*/
	if (ENEMY_STATE_DIE == state_)
	{
		return;
	}

	switch (aiType_)
	{
	case ENEMY_AI_TYPE_0:
	case ENEMY_AI_TYPE_1:[self ActionMovePath]; break;
	case ENEMY_AI_TYPE_2:
		switch (type_)
		{
		case 0:
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:[self ActionMove]; break;
		case 6:
		case 7: assert(false); break;
		case ENEMY_TYPE_BOSS_1:
		case ENEMY_TYPE_BOSS_2:
		case ENEMY_TYPE_BOSS_3:
			switch (rand() % 2)
			{
			case 0:[self ActionMove]; break;
			case 1:[self ActionAttack]; break;
			default:;
			}
			break;
		default:;
		}
		break;
	case ENEMY_AI_TYPE_3:[self ActionAttack]; break;
	default:;
	}
}

- (void)aiActionAttackOver
{
	int _Time;

	switch (aiType_)
	{
	case ENEMY_AI_TYPE_0: break;
	case ENEMY_AI_TYPE_1:[self ActionStand:standTime_]; break;
	case ENEMY_AI_TYPE_2:
		switch (type_)
		{
		case ENEMY_TYPE_0:
		case ENEMY_TYPE_1:
		case ENEMY_TYPE_2:
		case ENEMY_TYPE_3:
		case ENEMY_TYPE_4:
		case ENEMY_TYPE_5:
			_Time = rand() % 4 + 2;
			[self ActionStand:_Time];
			break;
		case ENEMY_TYPE_6:
		case ENEMY_TYPE_7:
			if (nil != [self GetFreeHeart])
			{
				[self ActionAttack];
			}
			else
			{
				[self ActionMove];
			}
			break;
		case ENEMY_TYPE_BOSS_1:
		case ENEMY_TYPE_BOSS_2:
		case ENEMY_TYPE_BOSS_3:
			switch (rand() % 2)
			{
			case 0:[self ActionMove]; break;
			case 1:
				_Time = rand() % 4 + 2;
				[self ActionStand:_Time];
				break;
			default:;
			}
			break;
		default:;
		}
		break;
	case ENEMY_AI_TYPE_3:[self ActionStand:5]; break;
	default:;
	}
}

- (void)stopAction
{
	[self stopAllActions];
	[image_ stopAllActions];
	image_.color = ccWHITE;
}

- (void)actionStand:(float)Time
{
	if (state_ == ENEMY_STATE_DIE)
	{
		return;
	}

	state_ = ENEMY_STATE_STAND;
	[self stopAction];
	[self playAniMove];
	[self runAction:tcCreateActionCallBack(self, Time, @selector(CallBackActionStandOver:))];
}

- (void)actionMovePath
{
	CGPoint _StartPos;
	CGPoint _EndPos;
	action_move_in_pixel *_ActionMove;
	CCCallFunc *_CallBackMoveOver;
	CCSequence *_Seq;

	if (state_ == ENEMY_STATE_DIE)
	{
		return;
	}

	state_ = ENEMY_STATE_MOVE;	
	[self stopAction];
	[self playAniMove];
	_StartPos = self.positionInPixels;
	_EndPos = movePath_.front();
	movePath_.pop_front();
	_ActionMove = tcCreateActionMove(_StartPos, _EndPos, [self GetMoveSpeed]);
	_CallBackMoveOver = [CCCallFunc actionWithTarget:self selector:@selector(CallBackActionMoveOver)];
	_Seq = [CCSequence actions:_ActionMove, _CallBackMoveOver, nil];
	[self runAction:_Seq];
}

- (void)actionMove
{
	/*valid area
	*/
	int _Enemy5ValidArea[4] = {0, 3, 2, 5};
	int _Boss1TailOutValidArea[6] = {3, 4, 5, 6, 7, 8};
	int _Boss3Stage2And3ValidArea[6] = {3, 4, 5, 6, 7, 8};

	int _AreaIndex;
	CGPoint _EndPos;

	CCSequence *_Seq;
	id _ActionMove;
	CCCallFuncN *_CallBack;

	if (state_ == ENEMY_STATE_DIE)
	{
		return;
	}

	state_ = ENEMY_STATE_MOVE;
	[self StopAction];
	[self PlayAni:ENEMY_ANI_MOVE];

	switch (type_)
	{
	case ENEMY_TYPE_0:
	case ENEMY_TYPE_1:
	case ENEMY_TYPE_2:
	case ENEMY_TYPE_3:
	case ENEMY_TYPE_4:
	case ENEMY_TYPE_6:
	case ENEMY_TYPE_7:
		_AreaIndex = rand() % 9;
		_EndPos = CfgGameGetPointCGPoint(_AreaIndex);
		break;
	case ENEMY_TYPE_5:
		_AreaIndex = _Enemy5ValidArea[rand() % 4];
		_EndPos = CfgGameGetPointCGPoint(_AreaIndex);
		break;
	case ENEMY_TYPE_BOSS_1:
		if (tailLeft_.flagActive)
		{
			_AreaIndex = _Boss1TailOutValidArea[rand() % 6];
		}
		else
		{
			_AreaIndex = rand() % 9;
		}
		_EndPos = g_CfgGameScrrenArea[_AreaIndex].center;
		break;
	case ENEMY_TYPE_BOSS_2:
		_AreaIndex = rand() % 9;
		_EndPos = g_CfgGameScrrenArea[_AreaIndex].center;
		break;
	case ENEMY_TYPE_BOSS_3:
		switch (flagBoss3Stage_)
		{
		case BOSS_3_STAGE_1:
			_AreaIndex = rand() % 9;
			_EndPos = g_CfgGameScrrenArea[_AreaIndex].center;
			break;
		case BOSS_3_STAGE_2:
		case BOSS_3_STAGE_3:
			_AreaIndex = _Boss3Stage2And3ValidArea[rand() % 6];
			_EndPos = g_CfgGameScrrenArea[_AreaIndex].center;
			break;
		default:;
		}
		break;
	default:;
	}

	_ActionMove = tcCreateActionMove(self.positionInPixels, _EndPos, [self GetMoveSpeed]);
	_CallBack = [CCCallFuncN actionWithTarget:self selector:@selector(CallBackActionMoveOver:)];
	_Seq = [CCSequence actions:_ActionMove, _CallBack, nil];
	[self runAction:_Seq];
}

- (void)actionAttack
{
	CCSequence *_Seq;
	id _Action;
	CCCallFuncN *_CallBackMoveOver;

	if (state_ == ENEMY_STATE_DIE)
	{
		return;
	}

	[self StopAction];
	switch (type_)
	{
	case ENEMY_TYPE_0: break;
	case ENEMY_TYPE_1:
	case ENEMY_TYPE_2:
	case ENEMY_TYPE_4:
	case ENEMY_TYPE_5:
		state_ = ENEMY_STATE_ATTACK;
		[self PlayAni:ENEMY_ANI_ATTACK];
		break;
	case ENEMY_TYPE_3:
		state_ = ENEMY_STATE_ATTACK;
		[self PlayAni:ENEMY_ANI_ATTACK];
		break;
	case ENEMY_TYPE_6:
		mouthHeartHandle_ = [self GetFreeHeart];
		if (nil != mouthHeartHandle_)
		{
			state_ = ENEMY_STATE_ATTACK;
			mouthHeartHandle_.flagMouth = true;
			mouthHeartHandle_.enemyMouthHandle = self;
			[self PlayAni:ENEMY_ANI_MOVE];
			[self PlayEffectMouth];
			_Action = tcCreateActionMove(self.positionInPixels, mouthHeartHandle_.positionInPixels, [self GetMoveSpeed]);
			_CallBackMoveOver = [CCCallFuncN actionWithTarget:self selector:@selector(CallBackActionMouthMoveToHeartOver:)];
			_Seq = [CCSequence actions:_Action, _CallBackMoveOver, nil];
			[self runAction:_Seq];
			[g_LayerGameObject ReorderEnemyMouth:self];
		}
		else
		{
			[self ActionMove];
		}
		break;
	case ENEMY_TYPE_7:
		mosquitoHeartHandle_ = [self GetFreeHeart];
		if (nil != mosquitoHeartHandle_)
		{
			state_ = ENEMY_STATE_ATTACK;
			mosquitoHeartHandle_.flagMosquito = true;
			mosquitoHeartHandle_.enemyMosquitoHandle = self;
			[self PlayAni:ENEMY_ANI_MOVE];
			[self PlayEffectMosquito];
			_Action = tcCreateActionMove(self.positionInPixels, ccp(mosquitoHeartHandle_.positionInPixels.x, mosquitoHeartHandle_.positionInPixels.y + 60), [self GetMoveSpeed]);
			_CallBackMoveOver = [CCCallFuncN actionWithTarget:self selector:@selector(CallBackActionMosquitoMoveToHeartOver:)];
			_Seq = [CCSequence actions:_Action, _CallBackMoveOver, nil];
			[self runAction:_Seq];
		}
		else
		{
			[self ActionMove];
		}
		break;
	case ENEMY_TYPE_BOSS_1:
	case ENEMY_TYPE_BOSS_2:
	case ENEMY_TYPE_BOSS_3:
		state_ = ENEMY_STATE_ATTACK;
		[self PlayAni:ENEMY_ANI_ATTACK];
		break;
	default:;
	}
}

- (void)actionDie
{
	std::list<sprite_game_enemy_skull *>::iterator _Iter;

	if (state_ == ENEMY_STATE_DIE)
	{
		return;
	}

	state_ = ENEMY_STATE_DIE;
	[self resumeSchedulerAndActions];
	[image_ resumeSchedulerAndActions];
	[self StopAction];
	[self PlayAni:ENEMY_ANI_DIE];
	[self DestroyBody];
	switch (type_)
	{
	case ENEMY_TYPE_5:
	{
		if (nil != boss3Handle_)
		{
			[boss3Handle_ ActionBoss3SlaveDead:self];
		}
		boss3Handle_ = nil;
	}
	break;
	case ENEMY_TYPE_BOSS_2:
	{
		[self EndTimerBoss2StartStrongAttack];
		_Iter = skullList_.begin();
		for (; _Iter != skullList_.end(); _Iter++)
		{
			[*_Iter DestroyBody];
			[*_Iter ActionDie];
		}
		skullList_.clear();
	}
	break;
	default:;
	}
	if (nil != mouthHeartHandle_)
	{
		mouthHeartHandle_.flagMouth = false;
		mouthHeartHandle_.enemyMouthHandle = nil;
	}
	if (nil != mosquitoHeartHandle_)
	{
		mosquitoHeartHandle_.flagMosquito = false;
		mosquitoHeartHandle_.enemyMosquitoHandle = nil;
	}
	mouthHeartHandle_ = nil;
	mosquitoHeartHandle_ = nil;

	/*effect
	*/
	EffectEnemyDie();
}

- (void)actionDamageTint
{
	CCSequence *_Seq;
	id _Action;
	CCCallFuncN *_CallBack;

	if (state_ == ENEMY_STATE_DIE)
	{
		return;
	}

	_Action = [CCTintTo actionWithDuration:ENEMY_DAMAGE_TINT_TIME red:255 green:0 blue:0];
	_CallBack = [CCCallFuncN actionWithTarget:self selector:@selector(CallBackActionDamageTintOver:)];
	_Seq = [CCSequence actions:_Action, _CallBack, nil];
	[image_ runAction:_Seq];
}

- (void)callBackActionMoveOver
{
	[self AiActionMoveOver];
}

- (void)callBackActionStandOver
{
	[self AiActionStandOver];
}

- (void)callBackActionAttackOver
{
	sprite_game_bomb *_Bomb;
	CGPoint _StartPos, _EndPos;
	float _Time;

	/*create bomb
	*/
	switch (type_)
	{
	case ENEMY_TYPE_0: break;
	case ENEMY_TYPE_1:
	case ENEMY_TYPE_2:
	case ENEMY_TYPE_3:
	case ENEMY_TYPE_5:
		_StartPos = self.positionInPixels;
		_StartPos.y -= g_CfgGameEnemyDataTable[type_].bomb_offset;
		_EndPos = [g_SpriteGameBridge GetBridgePositionByX:self.positionInPixels.x];
		_Time = ptPointDistance_CGPoint(self.positionInPixels, _EndPos) / 90.0f;
		_Bomb = [[sprite_game_bomb alloc] initSpriteGameBomb:g_CfgGameEnemyDataTable[type_].bomb_type];
		[g_LayerGameObject AddBomb:_Bomb];
		_Bomb.positionInPixels = _StartPos;
		[_Bomb ActionAttack:_Time And:_EndPos];
		break;
	case ENEMY_TYPE_4:
		_StartPos = self.positionInPixels;
		_StartPos.y -= g_CfgGameEnemyDataTable[type_].bomb_offset;
		_EndPos = [g_SpriteGameBridge GetBridgePositionByX:self.positionInPixels.x];
		_Time = ptPointDistance_CGPoint(self.positionInPixels, _EndPos) / 90.0f;
		/*1*/
		_Bomb = [[sprite_game_bomb alloc] initSpriteGameBomb:g_CfgGameEnemyDataTable[type_].bomb_type];
		[g_LayerGameObject AddBomb:_Bomb];
		_Bomb.positionInPixels = ccp(_StartPos.x - 50, _StartPos.y);
		[_Bomb ActionAttack:_Time And:ccp(_EndPos.x - 50, _EndPos.y)];
		/*2*/
		_Bomb = [[sprite_game_bomb alloc] initSpriteGameBomb:g_CfgGameEnemyDataTable[type_].bomb_type];
		[g_LayerGameObject AddBomb:_Bomb];
		_Bomb.positionInPixels = ccp(_StartPos.x + 50, _StartPos.y);
		[_Bomb ActionAttack:_Time And:ccp(_EndPos.x + 50, _EndPos.y)];
		break;
	case ENEMY_TYPE_6:
	case ENEMY_TYPE_7: break;
	case ENEMY_TYPE_BOSS_1:
		_StartPos = self.positionInPixels;
		_StartPos.y -= g_CfgGameBoss1Data.bomb_offset;
		_EndPos = [g_SpriteGameBridge GetBridgePositionByX:self.positionInPixels.x];
		_Time = ptPointDistance_CGPoint(self.positionInPixels, _EndPos) / 90.0f;
		_Bomb = [[sprite_game_bomb alloc] initSpriteGameBomb:g_CfgGameBoss1Data.bomb_type];
		[g_LayerGameObject AddBomb:_Bomb];
		_Bomb.positionInPixels = _StartPos;
		[_Bomb ActionAttack:_Time And:_EndPos];
		break;
	case ENEMY_TYPE_BOSS_2:
		_StartPos = self.positionInPixels;
		_StartPos.y -= g_CfgGameBoss2Data.bomb_offset;
		_EndPos = [g_SpriteGameBridge GetBridgePositionByX:self.positionInPixels.x];
		_Time = ptPointDistance_CGPoint(self.positionInPixels, _EndPos) / 90.0f;
		_Bomb = [[sprite_game_bomb alloc] initSpriteGameBomb:g_CfgGameBoss2Data.bomb_type];
		[g_LayerGameObject AddBomb:_Bomb];
		_Bomb.positionInPixels = _StartPos;
		[_Bomb ActionAttack:_Time And:_EndPos];
		break;
	case ENEMY_TYPE_BOSS_3:
		_StartPos = self.positionInPixels;
		_StartPos.y -= g_CfgGameBoss3Data.bomb_offset;
		_EndPos = [g_SpriteGameBridge GetBridgePositionByX:self.positionInPixels.x];
		_Time = ptPointDistance_CGPoint(self.positionInPixels, _EndPos) / 90.0f;
		_Bomb = [[sprite_game_bomb alloc] initSpriteGameBomb:g_CfgGameBoss3Data.bomb_type];
		[g_LayerGameObject AddBomb:_Bomb];
		_Bomb.positionInPixels = _StartPos;
		[_Bomb ActionAttack:_Time And:_EndPos];
		break;
	default:;
	}

	/*next ai action
	*/
	[self AiActionAttackOver];
}

- (void)callBackActionDieOver
{
	/*boss3 clear handle
	*/
	if (boss3SlaveLeftHandle_ != nil)
	{
		boss3SlaveLeftHandle_.boss3Handle = nil;
		[g_LayerGameObject RemoveEnemy:boss3SlaveLeftHandle_];
	}
	if (boss3SlaveRightHandle_ != nil)
	{
		boss3SlaveRightHandle_.boss3Handle = nil;
		[g_LayerGameObject RemoveEnemy:boss3SlaveRightHandle_];
	}

	switch (aiType_)
	{
	case ENEMY_AI_TYPE_0:
	case ENEMY_AI_TYPE_1:
	case ENEMY_AI_TYPE_2: CMgrGameMission::Instance()->EventEnemyKilled(self); break;
	case ENEMY_AI_TYPE_3:
		break;
	default:;
	}
	[g_LayerGameObject RemoveEnemy:self];
}

- (void)callBackActionDamageTintOver
{
	id _Action;

	_Action = [CCTintTo actionWithDuration:ENEMY_DAMAGE_TINT_TIME red:255 green:255 blue:255];
	[image_ runAction:_Action];
}

@end